package com.ruoyi.web.purchase.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.web.purchase.mapper.PurchaseMapper;
import org.springframework.stereotype.Service;
import com.ruoyi.web.purchase.domain.Purchase;
import com.ruoyi.web.purchase.service.IPurchaseService;

import javax.annotation.Resource;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 采购查询Service业务层处理
 * 
 * @author czr
 * @date 2024-08-14
 */
@Service
@DataSource(value = DataSourceType.SLAVE)
public class PurchaseServiceImpl implements IPurchaseService 
{
    @Resource
    private PurchaseMapper purchaseMapper;


    //first commit

    //更新代码 不包含图片 xxxxxxxxxxxxxxxxxxxx


    /**
     * 查询采购查询
     * 
     * @param ID 采购查询主键
     * @return 采购查询
     */
    @Override
    public Purchase selectPurchaseByID(Long ID)
    {
        return purchaseMapper.selectPurchaseByID(ID);
    }

    /**
     * 查询采购查询列表
     * 
     * @param purchase 采购查询
     * @return 采购查询
     */
    @Override
    public List<Purchase> selectPurchaseList(Purchase purchase)
    {
        return purchaseMapper.selectPurchaseList(purchase);
    }

    @Override
    public List<Purchase> getFundTest(String searchmonth) {
//        searchmonth = "2024-06";
        List<Purchase> fundTest = purchaseMapper.getFundTest(searchmonth);
        for (Purchase purchase : fundTest) {
            if (purchase.getHis()!=null && purchase.getIoriSum()!=null){
                purchase.setReduceCosts(purchase.getIoriSum().subtract(purchase.getHis()));
            }
        }
        return fundTest;
    }


    /**
     * 新增采购查询
     * 
     * @param purchase 采购查询
     * @return 结果
     */
    @Override
    public int insertPurchase(Purchase purchase)
    {
        return purchaseMapper.insertPurchase(purchase);
    }

    /**
     * 修改采购查询
     * 
     * @param purchase 采购查询
     * @return 结果
     */
    @Override
    public int updatePurchase(Purchase purchase)
    {
        return purchaseMapper.updatePurchase(purchase);
    }

    /**
     * 批量删除采购查询
     * 
     * @param IDs 需要删除的采购查询主键
     * @return 结果
     */
    @Override
    public int deletePurchaseByIDs(Long[] IDs)
    {
        return purchaseMapper.deletePurchaseByIDs(IDs);
    }

    /**
     * 删除采购查询信息
     * 
     * @param ID 采购查询主键
     * @return 结果
     */
    @Override
    public int deletePurchaseByID(Long ID)
    {
        return purchaseMapper.deletePurchaseByID(ID);
    }
}
